﻿/* 
 
This file is part of Ingo Karstein's Custom SharePoint 2010 Ribbon project

**Do not remove this comment**

Please see the project homepage at CodePlex:
  http://spcustomribbondemo.codeplex.com

Please see my blog:
  http://ikarstein.wordpress.com

Licence: GPLv2
    Ingo Karstein's SharePoint 2010 Custom Ribbon Demo
    Copyright (C) 2011  Ingo Karstein, ikarstein@hotmail.com

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ 

function ULS_SP() {
    if (ULS_SP.caller) {
        ULS_SP.caller.ULSTeamName = "Windows SharePoint Services 4";
        ULS_SP.caller.ULSFileName = "ikribbon.UI.js";
    }
}

Type.registerNamespace('ikribbon.UI');

//  Page Component
ikribbon.UI.PageComponent = function () {
    ULS_SP();
    ikribbon.UI.PageComponent.initializeBase(this);
}
ikribbon.UI.PageComponent.initialize = function () {
    ULS_SP();
    ExecuteOrDelayUntilScriptLoaded(Function.createDelegate(null, ikribbon.UI.PageComponent.initializePageComponent), 'SP.Ribbon.js');
}
ikribbon.UI.PageComponent.initializePageComponent = function () {
    ULS_SP();
    var ribbonPageManager = SP.Ribbon.PageManager.get_instance();
    if (null !== ribbonPageManager) {
        ribbonPageManager.addPageComponent(ikribbon.UI.PageComponent.instance);
        ribbonPageManager.get_focusManager().requestFocusForComponent(ikribbon.UI.PageComponent.instance);
    }
}
ikribbon.UI.PageComponent.refreshRibbonStatus = function () {
    SP.Ribbon.PageManager.get_instance().get_commandDispatcher().executeCommand(Commands.CommandIds.ApplicationStateChanged, null);
}
ikribbon.UI.PageComponent.prototype = {
    getFocusedCommands: function () {
        ULS_SP();
        return [];
    },
    getGlobalCommands: function () {
        ULS_SP();
        return getGlobalCommands();
    },
    isFocusable: function () {
        ULS_SP();
        return true;
    },
    receiveFocus: function () {
        ULS_SP();
        return true;
    },
    yieldFocus: function () {
        ULS_SP();
        return true;
    },
    canHandleCommand: function (commandId) {
        ULS_SP();
        return commandEnabled(commandId);
    },
    handleCommand: function (commandId, properties, sequence) {
        ULS_SP();
        return handleCommand(commandId, properties, sequence);
    }
}

var ikribbonActiveInterval = null;

function ikribbonActiveRibbonTab() {
    try {
        window.clearInterval(ikribbonActiveInterval);

        if (typeof (_ribbonStartInit) == "function") {
            _ribbonStartInit('ik.SharePoint2010.Ribbon.CustomTab', false, null);
        }

        if (true && typeof (_ribbonReadyForInit) == 'function' && !_ribbonReadyForInit()) {
            ikribbonActiveInterval = window.setInterval("ikribbonActiveRibbonTab()", 100);
        }
    } catch (e2) {
    };
};

function ikribbonInit() {
    //alert('ikribbonInit');
    ikribbon.UI.PageComponent.registerClass('ikribbon.UI.PageComponent', CUI.Page.PageComponent);
    ikribbon.UI.PageComponent.instance = new ikribbon.UI.PageComponent();
    ikribbon.UI.PageComponent.initialize();

    ExecuteOrDelayUntilScriptLoaded(ikribbonActiveRibbonTab, 'ikribbon.UI.js');
}

NotifyScriptLoadedAndExecuteWaitingJobs("ikribbon.UI.js");


